package edu.zhang.front.controller;

import java.io.IOException;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.naming.java.javaURLContextFactory;

import java.text.SimpleDateFormat;
import edu.zhang.dao.CustomerDAO;
import edu.zhang.dao.TypeDAO;
import edu.zhang.po.Customer;
import edu.zhang.po.Type;

@WebServlet("/customer/CustomerSubmited")
public class CustomerSubmited extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		String name = request.getParameter("name");
		String gender = request.getParameter("gender");
		String birthday = request.getParameter("birthday");
		String idcard = request.getParameter("idcard");
		String address = request.getParameter("address");
		String telephone = request.getParameter("telephone");
		String email = request.getParameter("email");
		String code = request.getParameter("code");
		
		Customer customer = new Customer();
		customer.setAccount(account);
		customer.setPassword(password);
		customer.setName(name);
		customer.setGender(gender);
		
		customer.setBirthday(birthday);
		
		customer.setIdcard(idcard);
		customer.setAddress(address);
		customer.setTelephone(telephone);
		customer.setEmail(email);
		customer.setCode(code);

		CustomerDAO customerDAO = new CustomerDAO();
		int i = customerDAO.update(customer);


		if (i > 0) {
			request.getRequestDispatcher("usercenter.jsp").forward(request, response);
		} else {
			response.sendRedirect("error.jsp");
		}
	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
